package cn.threewaters.qtyy.web.controller.business;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.baomidou.mybatisplus.plugins.Page;

import cn.threewaters.qtyy.common.bean.PageBean;
import cn.threewaters.qtyy.common.bean.ResponseJson;
import cn.threewaters.qtyy.dic.one.queryparam.QueryTfkz;
import cn.threewaters.qtyy.dic.one.queryresult.ResultTfkz;
import cn.threewaters.qtyy.service.business.TfkzService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

@Api(tags = "通风控制")
@Controller
@RequestMapping(value = "/tongfeng")
public class TfkzController {
	@Autowired
	private TfkzService tfkzService;

	@ApiIgnore
	@ApiOperation(value = "通风控制仓房概览页面")
	@RequestMapping(value = "/cfgl/main", method = RequestMethod.GET)
	public ModelAndView cfglMain(ModelMap modelMap, String lkbh) {
		return new ModelAndView("business/tongfeng/tongfengCfgl", modelMap);
	}

	@ApiIgnore
	@ApiOperation(value = "通风控制仓房详情页面")
	@RequestMapping(value = "/cfxq/main", method = RequestMethod.GET)
	public ModelAndView cfxqMain(ModelMap modelMap, String id) {
		modelMap.put("id", id);
		return new ModelAndView("business/tongfeng/tongfengCfxq", modelMap);
	}

	@ApiOperation(value = "概览")
	@RequestMapping(value = "/GLlist", method = RequestMethod.GET)
	@ResponseBody
	public ResponseJson getGLList(QueryTfkz queryTfkz) throws Exception {
		List<ResultTfkz> tfkzGLs = tfkzService.queryTfkzGL(queryTfkz);
		return ResponseJson.builder().success(true).obj(tfkzGLs).build();
	}

	@ApiOperation(value = "详情")
	@RequestMapping(value = "/XQlist", method = RequestMethod.GET)
	@ResponseBody
	public ResponseJson getXQList(QueryTfkz queryTfkz) throws Exception {
		List<ResultTfkz> tfkzXQs = tfkzService.queryTfkzXQ(queryTfkz);
		return ResponseJson.builder().success(true).obj(tfkzXQs).build();
	}

	@ApiOperation(value = "列表")
	@RequestMapping(value = "/LBlist", method = RequestMethod.GET)
	@ResponseBody
	public ResponseJson getLBList(PageBean page, QueryTfkz queryTfkz) throws Exception {
		String jcsj = queryTfkz.getJcsj();
		if (jcsj != null && jcsj.indexOf(" - ") > 0) {
			queryTfkz.setChecktimebegin(jcsj.split(" - ")[0]);
			queryTfkz.setChecktimestop(jcsj.split(" - ")[1]);
		}
		Page<ResultTfkz> pageResult = new Page<ResultTfkz>();
		List<ResultTfkz> tfkzLBs = tfkzService.queryTfkzGL(queryTfkz);
		pageResult.setRecords(tfkzLBs);
		pageResult.setTotal(tfkzLBs.size());
		return ResponseJson.builder().success(true).obj(pageResult).build();
	}

}
